import {Component} from '@angular/core';
import {IonicPage, NavController} from 'ionic-angular';
import {KitProvider} from "../../../core/foundations/KitProvider";
import {Customer} from "../../../models/Customer";

/**
 * Generated class for the MyAccountEditPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-my-account-edit',
  templateUrl: 'my-account-edit.html',
})
export class EmployeeMyAccountEditPage {
  userInfo: Customer;

  constructor(public nav: NavController, public kit: KitProvider) {
  }


  ionViewDidLoad() {
    console.log('ionViewDidLoad MyAccountEditPage');
    this.userInfo = this.kit.auth.userInfo();
  }

  save() {

    this.kit.auth.update(this.userInfo).subscribe(
      res => {
        if(res.success)
          this.kit.alertMsg('Success', 'User info is updated!');
        else
          this.kit.alertMsg('Error', 'Something of errors have occurred,User info isn\'t updated!');
        this.nav.popToRoot();

      }
    );
  }


}
